package com.sphd.restaurantsystem.model;


import com.android.volley.VolleyError;
import com.sphd.restaurantsystem.info.GoodSellInorOutInfo;
import com.sphd.restaurantsystem.interfaces.VolleyJsonObjectCallBack;
import com.sphd.restaurantsystem.presenter.GoodSellInorOutPresenterImpl;
import com.wzh.frame.utils.JsonUtil;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;

/**
* Created by Hu on 2016/12/26
*/

public class GoodSellInorOutModelImpl implements GoodSellInorOutModel{

    @Override
    public void sendUrl(String url, GoodSellInorOutPresenterImpl goodSellInorOutPresenter) {
        volleyUtil.setJsonObjectRequest(url, new VolleyJsonObjectCallBack() {
            @Override
            public void onResponse(JSONObject response) {
                try {
                    List<GoodSellInorOutInfo> goodSellInorOutInfos = JsonUtil.getListFromString(response.getString("list"),GoodSellInorOutInfo.class);
                    goodSellInorOutPresenter.sendList(goodSellInorOutInfos);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onErrorResponse(VolleyError error) {
                    goodSellInorOutPresenter.sendError(error);
            }
        });
    }
}